package com.ruoyi.web.controller.HbUser;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.HbUser.domain.HbUser;
import com.ruoyi.HbUser.service.IHbUserService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 红包用户中间 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-07-30
 */
@Controller
@RequestMapping("/HbUser/hbUser")
public class HbUserController extends BaseController
{
    private String prefix = "HbUser/hbUser";
	
	@Autowired
	private IHbUserService hbUserService;
	
	@RequiresPermissions("HbUser:hbUser:view")
	@GetMapping()
	public String hbUser()
	{
	    return prefix + "/hbUser";
	}
	
	/**
	 * 查询红包用户中间列表
	 */
	@RequiresPermissions("HbUser:hbUser:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(HbUser hbUser)
	{
		hbUser.setValid(1);
		startPage();
        List<HbUser> list = hbUserService.selectHbUserList(hbUser);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出红包用户中间列表
	 */
	@RequiresPermissions("HbUser:hbUser:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HbUser hbUser)
    {
    	List<HbUser> list = hbUserService.selectHbUserList(hbUser);
        ExcelUtil<HbUser> util = new ExcelUtil<HbUser>(HbUser.class);
        return util.exportExcel(list, "hbUser");
    }
	
	/**
	 * 新增红包用户中间
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存红包用户中间
	 */
	@RequiresPermissions("HbUser:hbUser:add")
	@Log(title = "红包用户中间", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(HbUser hbUser)
	{		
		return toAjax(hbUserService.insertHbUser(hbUser));
	}

	/**
	 * 修改红包用户中间
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		HbUser hbUser = hbUserService.selectHbUserById(id);
		mmap.put("hbUser", hbUser);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存红包用户中间
	 */
	@RequiresPermissions("HbUser:hbUser:edit")
	@Log(title = "红包用户中间", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(HbUser hbUser)
	{		
		return toAjax(hbUserService.updateHbUser(hbUser));
	}
	
	/**
	 * 删除红包用户中间
	 */
	@RequiresPermissions("HbUser:hbUser:remove")
	@Log(title = "红包用户中间", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(hbUserService.deleteHbUserByIds(ids));
	}
	
}
